﻿#region "Copyright (C) Lenny Granovsky. 2005-2013"
//This program is free software distribute under the terms of the GNU General Public License as published by
//the Free Software Foundation. Please read AssemblyInfo.cs file for more information.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Web.Enhancements.Rest.Filters
{
    /// <summary>
    /// <para>Attribute that allows to set request validation for potentially dangerous data for the REST service method.</para>
    /// <para>This attribute is an optional. By default request is validated if attribute is set to the method.</para>
    /// </summary>
    [Serializable()]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class ValidateRequestAttribute : WebRestFilterAttribute
    {
        /// <summary>
        /// Gets or sets the if REST service method requires request validation.
        /// </summary>
        public bool RequiresValidation { get; set; }

        /// <summary>
        /// Default class constructor.
        /// </summary>
        public ValidateRequestAttribute()
            : base()
        {
            this.RequiresValidation = true;
        }

        /// <summary>
        /// Class constructor that accepts request validation requirement.
        /// </summary>
        /// <param name="requiresValidation">Boolean value indicated if request validation is required.</param>
        public ValidateRequestAttribute(bool requiresValidation)
            : base()
        {
            this.RequiresValidation = requiresValidation;
        }

        public override System.Type FilterType
        {
            get
            {
                return typeof(ValidateRequestFilter);
            }
            set
            {
                //does nothing - should not reset value. //just for interface
            }
        }

        public override IWebRestFilter CreateFilter()
        {
            return new ValidateRequestFilter()
            {
                RequiresValidation = this.RequiresValidation
            };
        }
    }
}
